home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / Javacup / PR8ADPL7.TAR / productivity_tools / PR8ADPL7 / JFSapplet.java < prev    next >
Encoding:
Java Source  |  1996-05-23  |  2.0 KB  |  92 lines

  1. // JFSapplet
  2. // This applet exists only to connect to a JFS server, and then run a
  3. // JFScomponent in the applet window.
  4. import java.awt.*;
  5. import java.io.*;
  6. import JFScomponent;
  7. import BorderPanel;
  8.  
  9. public class JFSapplet extends java.applet.Applet
  10. {
  11.     LoginWindow lw;
  12.     JFScomponent co;
  13.     JFSclient con;
  14.  
  15.     public void start()
  16.     {
  17.     // Get, load and add the component
  18.     String compstr = getParameter("component");
  19.     if (compstr == null)
  20.         die("No component parameter given");
  21.     Class c = null;
  22.     try c = Class.forName(compstr);
  23.     catch(ClassNotFoundException e)
  24.         die("Class not found!");
  25.     try co = (JFScomponent)c.newInstance();
  26.     catch(InstantiationException e)
  27.         die("Could not instantiate class");
  28.     catch(IllegalAccessException e)
  29.         die("Illegal access to class");
  30.     co.init(this);
  31.     setLayout(new BorderLayout());
  32.     BorderPanel main = new BorderPanel(new Color(220,220,200), Color.black);
  33.     main.setLayout(new BorderLayout());
  34.     main.add("Center",co);
  35.     add("Center",main);
  36.  
  37.     // Get the user's name and password (from param or requestor)
  38.     String n = getParameter("username");
  39.     String p = getParameter("password");
  40.     if (n != null && p != null)
  41.         login(n,p);
  42.     else
  43.         lw = new LoginWindow(this);
  44.     }
  45.  
  46.     // stop
  47.     // Disconnect from the JFS server
  48.     public void stop()
  49.     {
  50.     if (con != null) {
  51.         con.close();
  52.         con = null;
  53.         }
  54.     }
  55.  
  56.     // action
  57.     // Handle user input (from the login window)
  58.     public boolean action(Event evt, Object o)
  59.     {
  60.     if (evt.target == lw && evt.arg.equals("Ok"))
  61.         login(lw.getname(), lw.getpass());
  62.     return true;
  63.     }
  64.  
  65.     // login
  66.     // Connect to the server once a name and password have been
  67.     // somehow acquired
  68.     void login(String name, String pass)
  69.     {
  70.     try con = new JFSclient(getCodeBase().getHost());
  71.     catch(IOException e) {
  72.         new ErrorWindow("Failed to connect to server");
  73.         return;
  74.         }
  75.     try con.auth(name, pass);
  76.     catch(RequestException e) {
  77.         new ErrorWindow("Login failed : "+e.getMessage());
  78.         return;
  79.         }
  80.     co.connect(con);
  81.     }
  82.  
  83.     // die
  84.     // Print a message and quit
  85.     void die(String m)
  86.     {
  87.     System.out.println(m);
  88.     System.exit(1);
  89.     }
  90. }
  91.  
  92.